<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
<html>
<title>Bloomberg Development Environment</title>
<html>
<pre>
// Copyright 2019-2023 Bloomberg Finance L.P.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// bmqa_openqueuestatus.h                                             -*-C++-*-
#ifndef INCLUDED_BMQA_OPENQUEUESTATUS
#define INCLUDED_BMQA_OPENQUEUESTATUS

//@PURPOSE: Provide Value-Semantic Type for an open queue operation status
//
//@CLASSES:
//  bmqa::OpenQueueStatus: value-semantic type for an openQueue result
//
//@DESCRIPTION: This component provides a specific value-semantic type for the
// result of an open queue operation with the BlazingMQ broker, providing
// applications with the result and context of the requested operation.
//
// A &#39;bmqa::OpenQueueStatus&#39; type is composed of 3 attributes:
//: o !result!:           indicates the status of the operation (success,
//:                       failure, etc.) as specified in the corresponding
//:                       result code enum, &#39;bmqt::OpenQueueResult::Enum&#39;
//: o !queueId!:          queueId associated with the open queue operation
//: o !errorDescription!: optional string with a human readable description of
//:                       the error, if any


// BMQ
#include &lt;bmqscm_version.h&gt;
#include &lt;bmqa_queueid.h&gt;
#include &lt;bmqt_resultcode.h&gt;

// BDE
#include &lt;bsl_iostream.h&gt;
#include &lt;bsl_string.h&gt;
#include &lt;bslma_allocator.h&gt;
#include &lt;bslma_default.h&gt;
#include &lt;bslma_usesbslmaallocator.h&gt;
#include &lt;bslmf_nestedtraitdeclaration.h&gt;


namespace BloombergLP {
namespace bmqa {

                           // =====================
                           // class OpenQueueStatus
                           // =====================

class OpenQueueStatus {
    // A value-semantic type for an open queue operation with the message queue
    // broker.

  private:
    // DATA
    QueueId                     d_queueId;
                                        // queueId associated with the open
                                        // queue operation

    bmqt::OpenQueueResult::Enum d_result;
                                        // Result code of the operation
                                        // (success, failure)

    bsl::string                 d_errorDescription;
                                        // Optional string with a human
                                        // readable description of the error,
                                        // if any

  public:
    // TRAITS
    BSLMF_NESTED_TRAIT_DECLARATION(OpenQueueStatus, bslma::UsesBslmaAllocator)

    // CREATORS
    explicit OpenQueueStatus(bslma::Allocator *allocator = 0);
        // Default constructor, use the optionally specified &#39;allocator&#39;.

    OpenQueueStatus(const bmqa::OpenQueueStatus&amp;  other,
                    bslma::Allocator             *allocator = 0);
        // Create a new &#39;bmqa::OpenQueueStatus&#39; using the optionally specified
        // &#39;allocator&#39;.

    OpenQueueStatus(const QueueId&amp;               queueId,
                    bmqt::OpenQueueResult::Enum  result,
                    const bsl::string&amp;           errorDescription,
                    bslma::Allocator            *allocator        = 0);
        // Create a new &#39;bmqa::OpenQueueStatus&#39; object having the specified
        // &#39;queueId&#39;, &#39;result&#39;, and &#39;errorDescription&#39;, using the
        // optionally specified &#39;allocator&#39; to supply memory.

    // MANIPULATORS
    OpenQueueStatus&amp; operator=(const OpenQueueStatus&amp; rhs);
        // Assignment operator from the specified &#39;rhs&#39;.

    // ACCESSORS
    operator bool() const;
        // Return true if this result indicates success, and false otherwise.

    const QueueId&amp; queueId() const;
        // Return the queueId associated to this operation result, if any.

    bmqt::OpenQueueResult::Enum result() const;
        // Return the result code that indicates success or the cause of a
        // failure.

    const bsl::string&amp; errorDescription() const;
        // Return a printable description of the error, if &#39;result&#39; indicates
        // failure.  Return an empty string otherwise.

    bsl::ostream&amp; print(bsl::ostream&amp; stream,
                        int           level          = 0,
                        int           spacesPerLevel = 4) const;
        // Format this object to the specified output &#39;stream&#39; at the (absolute
        // value of) the optionally specified indentation &#39;level&#39; and return a
        // reference to &#39;stream&#39;.  If &#39;level&#39; is specified, optionally specify
        // &#39;spacesPerLevel&#39;, the number of spaces per indentation level for
        // this and all of its nested objects.  If &#39;level&#39; is negative,
        // suppress indentation of the first line.  If &#39;spacesPerLevel&#39; is
        // negative format the entire output on one line, suppressing all but
        // the initial indentation (as governed by &#39;level&#39;).  If &#39;stream&#39; is
        // not valid on entry, this operation has no effect.
};

// FREE OPERATORS
bool operator==(const OpenQueueStatus&amp; lhs, const OpenQueueStatus&amp; rhs);
    // Return &#39;true&#39; if the specified &#39;rhs&#39; object contains the value of the
    // same type as contained in the specified &#39;lhs&#39; object and the value
    // itself is the same in both objects, return false otherwise.

bool operator!=(const OpenQueueStatus&amp; lhs, const OpenQueueStatus&amp; rhs);
    // Return &#39;false&#39; if the specified &#39;rhs&#39; object contains the value of the
    // same type as contained in the specified &#39;lhs&#39; object and the value
    // itself is the same in both objects, return &#39;true&#39; otherwise.

bsl::ostream&amp; operator&lt;&lt;(bsl::ostream&amp; stream, const OpenQueueStatus&amp; rhs);
    // Format the specified &#39;rhs&#39; to the specified output &#39;stream&#39; and return a
    // reference to the modifiable &#39;stream&#39;.

// ============================================================================
//                             INLINE DEFINITIONS
// ============================================================================

                           // ---------------------
                           // class OpenQueueStatus
                           // ---------------------

// CREATORS
inline
OpenQueueStatus::OpenQueueStatus(bslma::Allocator *allocator)
: d_queueId(allocator)
, d_result(bmqt::OpenQueueResult::e_SUCCESS)
, d_errorDescription(allocator)
{
    // NOTHING
}

inline
OpenQueueStatus::OpenQueueStatus(const OpenQueueStatus&amp;  other,
                                 bslma::Allocator       *allocator)
: d_queueId(other.d_queueId, allocator)
, d_result(other.d_result)
, d_errorDescription(other.d_errorDescription, allocator)
{
    // NOTHING
}

inline
OpenQueueStatus::OpenQueueStatus(const QueueId&amp;               queueId,
                                 bmqt::OpenQueueResult::Enum  result,
                                 const bsl::string&amp;           errorDescription,
                                 bslma::Allocator            *allocator)
: d_queueId(queueId, allocator)
, d_result(result)
, d_errorDescription(errorDescription)
{
    // NOTHING
}

// MANIPULATORS
inline
OpenQueueStatus&amp;
OpenQueueStatus::operator=(const OpenQueueStatus&amp; other)
{
    d_queueId          = other.queueId();
    d_result           = other.result();
    d_errorDescription = other.errorDescription();
    return *this;
}

// ACCESSORS
inline
OpenQueueStatus::operator bool() const
{
    return d_result == bmqt::OpenQueueResult::e_SUCCESS;
}

inline
const QueueId&amp;
OpenQueueStatus::queueId() const
{
    return d_queueId;
}

inline
bmqt::OpenQueueResult::Enum
OpenQueueStatus::result() const
{
    return d_result;
}

inline
const bsl::string&amp;
OpenQueueStatus::errorDescription() const
{
    return d_errorDescription;
}

}  // close package namespace

// FREE OPERATORS
inline
bsl::ostream&amp;
bmqa::operator&lt;&lt;(bsl::ostream&amp;                stream,
                 const bmqa::OpenQueueStatus&amp; rhs)
{
    return rhs.print(stream, 0, -1);
}

inline
bool
bmqa::operator==(const bmqa::OpenQueueStatus&amp; lhs,
                 const bmqa::OpenQueueStatus&amp; rhs)
{
    return    lhs.queueId()          == rhs.queueId()
           &amp;&amp; lhs.result()           == rhs.result()
           &amp;&amp; lhs.errorDescription() == rhs.errorDescription();
}

inline
bool
bmqa::operator!=(const bmqa::OpenQueueStatus&amp; lhs,
                 const bmqa::OpenQueueStatus&amp; rhs)
{
    return !(lhs == rhs);
}

}  // close enterprise namespace

#endif
</pre>
</body>
</html>
